import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
// 导入 Element Plus 中英文语言包
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import en from 'element-plus/es/locale/lang/en';

const useSettingStore = defineStore(
  'setting',
  () => {
    // 默认语言
    const language = ref('zh-cn');

    /**
     * 切换语言
     */
    const changeLanguage = (lang: string) => {
      language.value = lang;
    };

    const locale = computed(() => {
      if (language.value === 'zh-cn') {
        return zhCn;
      } else {
        return en;
      }
    });

    const asideActive = ref(false); // active 侧边栏为半展开状态
    const asideExpand = ref(false); // expand 侧边栏为全展开状态

    const currentMenuItem = ref(''); // 保存当前激活的菜单项

    const expand = computed(() => asideActive.value || asideExpand.value);

    const setAsideFold = () => {
      asideActive.value = false;
      asideExpand.value = false;
    };

    const setAsideExpand = () => {
      asideExpand.value = true;
      asideActive.value = true;
    };

    const setAsideActive = () => {
      asideActive.value = true;
      asideExpand.value = false;
    };

    return {
      language,
      locale,
      expand,
      asideActive,
      asideExpand,
      currentMenuItem,
      setAsideFold,
      setAsideActive,
      setAsideExpand,
      changeLanguage,
    };
  },
  {
    persist: true, // 开启持久化存储
  },
);

export default useSettingStore;
